package com.twu.biblioteca.Books;

import com.twu.biblioteca.Menus.BookMenu;

import java.util.ArrayList;
import java.util.List;

public class BookCollection {
    private List<Book> allBooks;

    public BookCollection(){
        this.allBooks = new ArrayList<Book>();
        this.setAllBooks();
    }

    public List<Book> getAllBooks() {
        return allBooks;
    }

    public void setAllBooks() {
        allBooks.add(new Book("Design Pattern"));
        allBooks.add(new Book("Test Driven Development"));
    }

    private boolean bookExistOrNot(Book book){
        return allBooks.contains(book);
    }

    public void reserveBook(Book book){
        BookMenu libraryMenu = new BookMenu();
        if(book.getReserve()){
            libraryMenu.BookReservedMessage(false);
        }else{
            if(bookExistOrNot(book)) {
                book.setReserve(true);
                libraryMenu.BookReservedMessage(true);
            }else{
                libraryMenu.BookReservedMessage(false);
            }
        }
    }

    public Book getBook(String bookName) {
        for(Book book : allBooks){
            if(book.getBookName().equals(bookName))
            {return book;}
        }
        return null;
    }
}
